package com.ruoyi.common.pms.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.pms.entity.YytPmsSkuInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.vo.ClassBySkuInfoVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * sku信息 Mapper 接口
 * </p>
 *
 * @author huangshun
 * @since 2021-12-16
 */
@Repository
public interface YytPmsSkuInfoMapper extends BaseMapper<YytPmsSkuInfo> {

    /**
     * 根据skuId获取详情信息 级联相关信息
     */
    @Select("select * from yyt_pms_sku_info where sku_id = #{skuId}")
    @Results({
            @Result(property = "skuId", column = "sku_id"),
            @Result(property = "spuId", column = "spu_id"),
            @Result(property = "brandId", column = "brand_id"),
            @Result(property = "shopId", column = "shop_id"),
            @Result(property = "skuImages", column = "sku_id", many = @Many(select = "com.ruoyi.common.pms.dao.YytPmsSkuImagesMapper.getImages")),
            @Result(property = "spuInfo", column = "spu_id", one = @One(select = "com.ruoyi.common.pms.dao.YytPmsSpuInfoMapper.selectById")),
            @Result(property = "spuImages", column = "spu_id", many = @Many(select = "com.ruoyi.common.pms.dao.YytPmsSpuImagesMapper.listBySpuId")),
            @Result(property = "spuInfoDesc", column = "spu_id", one = @One(select = "com.ruoyi.common.pms.dao.YytPmsSpuInfoDescMapper.selectById")),
            @Result(property = "shop", column = "shop_id", one = @One(select = "com.ruoyi.common.pms.dao.YytShopMapper.selectById")),
            @Result(property = "saleAttrValue", column = "sku_id",
                    many = @Many(select = "com.ruoyi.common.pms.dao.YytPmsSkuSaleAttrValueMapper.getBySkuId")),
            @Result(property = "brandName", column = "brand_id", one = @One(select = "com.ruoyi.common.pms.dao.YytPmsBrandMapper.getName"))
    })
    YytPmsSkuInfo getInfo(String skuId);

    /**
     * 根据skuIds获取详情列表 级联相关信息
     */
    @Select("select * from yyt_pms_sku_info where sku_id in(${skuIds}) order by shop_id")
    @Results({
            @Result(property = "skuId", column = "sku_id"),
            @Result(property = "skuImages", column = "sku_id", many = @Many(select = "com.ruoyi.common.pms.dao.YytPmsSkuImagesMapper.getImages")),
            @Result(property = "spuInfo", column = "spu_id", one = @One(select = "com.ruoyi.common.pms.dao.YytPmsSpuInfoMapper.selectById")),
            @Result(property = "spuImages", column = "spu_id", many = @Many(select = "com.ruoyi.common.pms.dao.YytPmsSpuImagesMapper.listBySpuId")),
            @Result(property = "shop", column = "shop_id", one = @One(select = "com.ruoyi.common.pms.dao.YytShopMapper.selectById")),
            @Result(property = "saleAttrValue", column = "sku_id",
                    many = @Many(select = "com.ruoyi.common.pms.dao.YytPmsSkuSaleAttrValueMapper.getBySkuId")),
            @Result(property = "brandName", column = "brand_id", one = @One(select = "com.ruoyi.common.pms.dao.YytPmsBrandMapper.getName"))
    })
    List<YytPmsSkuInfo> getInfoList(String skuIds);

    /**
     * 获取店铺商品分页列表
     */
//    @Select("select * from yyt_pms_sku_info ${ew.customSqlSegment}")
//    @Results({
//            @Result(property = "skuId", column = "sku_id"),
//            @Result(property = "skuDefaultImg", column = "sku_id", one = @One(select = "com.ruoyi.common.pms.dao.YytPmsSkuImagesMapper.getImageUrl"))
//    })
//    Page<YytPmsSkuInfo> getPage(Page<YytPmsSkuInfo> page,@Param(Constants.WRAPPER) Wrapper<YytPmsSkuInfo> wrapper);



    Page<YytPmsSkuInfo> getPage(Page<YytPmsSkuInfo> page, @Param("shopId") String shopId, @Param("searchVal") String searchVal);

    /**
     * 减库存
     * @param skuId
     * @param number
     * @return
     */
    Boolean reduceInventory(String skuId, Integer number);

    List<ClassBySkuInfoVo> getClassBySkuInfo(@Param("classId") String classId, @Param("sortValue") String sortValue, @Param("userId") String userId, @Param("sqType") Integer sqType);

    List<ClassBySkuInfoVo> getChildData(@Param("classId") String classId, @Param("sortValue") String sortValue, @Param("userId") String userId, @Param("sqType") Integer sqType);

    List<YytPmsSkuInfo> getSwiperList();
}
